import React, { Component } from 'react'
import { Route, Redirect } from 'react-router-dom'
import { hasToekn } from 'utils/storage'

export default class AUthRoute extends Component {
  render() {
    const { component: Comments, ...rest } = this.props
    return (
      <Route
        {...rest}
        render={(props) => {
          if (hasToekn()) {
            return <Comments {...props}></Comments>
          } else {
            return (
              // 路由 传参 search 查询字符串方式 state 对象方式
              <Redirect
                to={{
                  pathname: '/login',
                  // search: '?name=11&age=22',
                  state: {
                    pathname: props.location.pathname,
                  },
                }}
              ></Redirect>
            )
          }
        }}
      ></Route>
    )
  }
}
